package ems.dev.easycode.util;

import cn.hutool.core.util.StrUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 狠穿
 * @version 1.0.0
 * @date 2023/5/27
 * @function
 */
public class MappingUtil {

    private static Map<String ,String> loadTableAndPageMapping(){
        Map map = new HashMap();
        String mappings = PropertiesUtil.getProValueStr(Constant.EASY_CODE_PROPERTIES_FILE_NAME, Constant.EASYCODE_TABLE_PAGE_MAPPING);
        if(StrUtil.isBlank(mappings)){
            return new HashMap<>();
        }
        mappings = mappings.replace(" ", "");
        if(StrUtil.endWith(mappings,",")){
            mappings = mappings.substring(0,mappings.lastIndexOf(","));
        }
        List<String> mapping = StrUtil.split(mappings, ",");
        for (String mp : mapping) {
            List<String> split = StrUtil.split(mp, "=");
            map.put(split.get(0),split.get(1));
        }
        return map;
    }

    public static String getPageNo(String table){
        return loadTableAndPageMapping().get(table);
    }
}
